package com.ruoyi.project.wenyanwen.export.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wenyanwen.export.domain.SqliteExport;
import com.ruoyi.project.wenyanwen.export.service.ISqliteExportService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 数据表配置Controller
 * 
 * @author shixiangwen
 * @date 2020-09-27
 */
@Controller
@RequestMapping("/wenyanwen/export")
public class SqliteExportController extends BaseController
{
    private String prefix = "wenyanwen/export";

    @Autowired
    private ISqliteExportService sqliteExportService;

    @RequiresPermissions("wenyanwen:export:view")
    @GetMapping()
    public String export()
    {
        return prefix + "/export";
    }

    /**
     * 查询数据表配置列表
     */
    @RequiresPermissions("wenyanwen:export:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SqliteExport sqliteExport)
    {
        startPage();
        List<SqliteExport> list = sqliteExportService.selectSqliteExportList(sqliteExport);
        return getDataTable(list);
    }

    /**
     * 导出数据表配置列表
     */
    @RequiresPermissions("wenyanwen:export:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SqliteExport sqliteExport)
    {
        List<SqliteExport> list = sqliteExportService.selectSqliteExportList(sqliteExport);
        ExcelUtil<SqliteExport> util = new ExcelUtil<SqliteExport>(SqliteExport.class);
        return util.exportExcel(list, "export");
    }

    /**
     * 新增数据表配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据表配置
     */
    @RequiresPermissions("wenyanwen:export:add")
    @Log(title = "数据表配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SqliteExport sqliteExport)
    {
        return toAjax(sqliteExportService.insertSqliteExport(sqliteExport));
    }

    /**
     * 修改数据表配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SqliteExport sqliteExport = sqliteExportService.selectSqliteExportById(id);
        mmap.put("sqliteExport", sqliteExport);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据表配置
     */
    @RequiresPermissions("wenyanwen:export:edit")
    @Log(title = "数据表配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SqliteExport sqliteExport)
    {
        return toAjax(sqliteExportService.updateSqliteExport(sqliteExport));
    }

    /**
     * 删除数据表配置
     */
    @RequiresPermissions("wenyanwen:export:remove")
    @Log(title = "数据表配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sqliteExportService.deleteSqliteExportByIds(ids));
    }
}
